package com.bgs.eat.menuBack.controller;

import com.bgs.eat.config.CommonResult;
import com.bgs.eat.menuBack.entity.MenuBackEntity;
import com.bgs.eat.menuBack.service.MenuBackService;
import com.bgs.eat.roleBack.entity.RoleBackEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName MenuBackController
 * @Description TODO
 * @Author cjl
 * @Date 2022/10/12 10:20
 **/
@RestController
@CrossOrigin
@RequestMapping("menuBack")
public class MenuBackController {

    @Autowired
    MenuBackService menuBackService;


//    @GetMapping("getMenuInfos")
//    public CommonResult getMenuInfos(String id){
//        List<MenuBackEntity> menuManagerEntities = menuBackService.getMenuInfos(id);
//        if (menuManagerEntities!=null){
//            return CommonResult.ok(menuManagerEntities);
//        }else{
//            return CommonResult.error("错误");
//        }
//    }

    /**
    * @Author cjl
    * @Description 根据用户权限查询菜单（权限菜单）
    * @Date  15:47
    * @Return com.bgs.eat.config.CommonResult
    * @param id
    */
    @GetMapping("listMenuByRoleId")
    public CommonResult listMenuByRoleId(Integer id){
        List<MenuBackEntity> menuManagerEntities = menuBackService.listMenuByRoleId(id);
        if (menuManagerEntities!=null){
            return CommonResult.ok(menuManagerEntities);
        }else{
            return CommonResult.error("错误");
        }
    }

    /**
    * @Author cjl
    * @Description 树形菜单管理全查
    * @Date  13:30
    * @Return com.bgs.eat.config.CommonResult
    */
    @GetMapping("/selectMenuBackEntity")
    CommonResult selectMenuBackEntity(){
        List<MenuBackEntity> list = menuBackService.selectMenuBackEntity();
        return CommonResult.ok(list);
    }

    /**
    * @Author cjl
    * @Description 添加或修改菜单管理
    * @Date  15:51
    * @Return com.bgs.eat.config.CommonResult
    * @param menuBackEntity
    */
    @PostMapping("saveOrUpdateMenuBackEntity")
    CommonResult saveOrUpdateMenuBackEntity(MenuBackEntity menuBackEntity){
        int i = menuBackService.saveOrUpdateMenuBackEntity(menuBackEntity);
        if (i!=0){
            return CommonResult.ok();
        }else {
            return CommonResult.error("添加或修改失败!!!");
        }
    }

    /**
    * @Author cjl
    * @Description 删除菜单管理
    * @Date  15:52
    * @Return java.lang.Integer
    * @param id
    */
    @DeleteMapping("deleteMenuBackEntityById")
    Integer deleteMenuBackEntityById(Integer id){
        return menuBackService.deleteMenuBackEntityById(id);
    }



}
